package java8.stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author 周宇
 * @create 2020-05-20 10:31
 * 字符串转字符
 */
public class ToggleAPI {
    public static Stream<Character> getCharByStr(String str) {
        List<Character> characterList = new ArrayList<>();
        for (Character c : str.toCharArray()) {
            characterList.add(c);
        }
        return characterList.stream();
    }

    public static void main(String[] args) {
        String[] hw = {"Hello", "World"};
        Arrays.stream(hw).map(ToggleAPI::getCharByStr).forEach(stream -> stream.forEach(System.out::print));
        System.out.println("\n-------------------------------------------");
        Arrays.stream(hw).flatMap(ToggleAPI::getCharByStr).forEach(c -> System.out.print(c + " "));
        System.out.println("\n-------------------------------------------");
    }
}